package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class DiveCertification implements Parcelable, Comparable<DiveCertification> {

    private static final String TAG = DiveCertification.class.getName();

    private long mId;
    private long mDate;
    private DiveCourse mCourse;
    private DiveCenter mCenter;
    private String mNumber;

    public DiveCertification() {}

    public DiveCertification(long id, long date, DiveCourse course, DiveCenter center, String number) {
        this.setId(id);
        this.setDate(date);
        this.setCourse(course);
        this.setCenter(center);
        this.setNumber(number);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public long getDate() {
        return mDate;
    }

    public void setDate(long date) {
        this.mDate = date;
    }

    public DiveCourse getCourse() {
        return mCourse;
    }

    public void setCourse(DiveCourse course) {
        this.mCourse = course;
    }

    public DiveCenter getCenter() {
        return mCenter;
    }

    public void setCenter(DiveCenter center) {
        this.mCenter = center;
    }

    public String getNumber() {
        return mNumber;
    }

    public void setNumber(String number) {
        this.mNumber = number;
    }

    public String getFullName() {
        DiveCourse course = getCourse();
        if (course != null) {
            return course.getFullName();
        }
        return null;
    }

    public String getName() {
        DiveCourse course = getCourse();
        if (course != null) {
            return course.getName();
        }
        return null;
    }

    @Override
    public int compareTo(@NonNull DiveCertification another) {
        return ((Long) this.mDate).compareTo(another.mDate);
    }

    @Override
    public String toString() {
        return getFullName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeLong(mDate);
        dest.writeParcelable(mCourse, flags);
        dest.writeParcelable(mCenter, flags);
        dest.writeString(mNumber);
    }

    public static final Parcelable.Creator<DiveCertification> CREATOR = new Parcelable.Creator<DiveCertification>() {

        public DiveCertification createFromParcel(Parcel in) {
            return new DiveCertification(in);
        }

        public DiveCertification[] newArray(int size) {
            return new DiveCertification[size];
        }
    };

    private DiveCertification(Parcel in) {
        mId = in.readLong();
        mDate = in.readLong();
        mCourse = in.readParcelable(DiveCourse.class.getClassLoader());
        mCenter = in.readParcelable(DiveCenter.class.getClassLoader());
        mNumber = in.readString();
    }
}
